﻿@inherits AdminCompontentBase
<div class="fill-hover caption regular2--text text-justify line-clamp-2 rounded-lg pa-4">
    <dl class="d-flex justify-space-between item align-center mb-6">
        <dt class="d-inline-flex body2 regular--text">
            <span>@T($"DisplayName.SmsTemplateType.{Enum.GetName(typeof(SmsTemplateTypes), MessageTemplate.TemplateType)}")</span>
        </dt>
        <dd class="body2 regular3--text">@T("DisplayName.MessageTemplateTemplateType")</dd>
    </dl>
    <dl class="d-flex justify-space-between item align-center mb-6">
        <dt class="d-inline-flex body2 regular--text">
            <span>@MessageTemplate.DisplayName</span>
        </dt>
        <dd class="body2 regular3--text">@T("DisplayName.MessageTemplateDisplayName")</dd>
    </dl>
    <dl class="d-flex justify-space-between item align-center mb-6">
        <dt class="template-content d-inline-flex body2 regular--text">
            <span>@MessageTemplate.Content</span>
        </dt>
        <dd class="body2 regular3--text">@T("DisplayName.MessageTemplateContent")</dd>
    </dl>
    <MessageTemplateItems @bind-Value="MessageTemplate.Items" OnEditChanged="HandleTemplateItemChanged"></MessageTemplateItems>
</div>

@code {
    [EditorRequired]
    [Parameter]
    public MessageTemplateUpsertDto MessageTemplate { get; set; } = null!;

    private void HandleTemplateItemChanged(MessageTemplateItemChangedEventArgs args)
    {
        string startstr = "${";
        string endstr = "}";
        MessageTemplate.Title = MessageTemplate.Title.Replace($"{startstr}{args.OldCode}{endstr}", $"{startstr}{args.NewCode}{endstr}");
        MessageTemplate.Content = MessageTemplate.Content.Replace($"{startstr}{args.OldCode}{endstr}", $"{startstr}{args.NewCode}{endstr}");
    }
}
